﻿/*   
    Copyright (C) 2009 Galaktika Corporation ZAO

    This file is a part of Galaktika.BusinessMonitor
 
    Galaktika.BusinessMonitor is a free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
      
    You should have received a copy of the GNU General Public License
    along with Galaktika.BusinessMonitor.  If not, see <http://www.gnu.org/licenses/>.
  
    If GPL v.3 is not suitable for your products or company,
    Galaktika Corp provides Galaktika.BusinessMonitor under a flexible commercial license
    designed to meet your specific usage and distribution requirements.
    If you have already obtained a commercial license from Galaktika Corp,
    you can use this file under those license terms.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

[assembly: Galaktika.BI.Extensibility.ProvideExtension(typeof(Galaktika.BI.Addin.VisifireChart.AddinProvider))]
[assembly: Galaktika.BI.Extensibility.IncludeAssembly("Galaktika.BI.Addin.VisifireChart.Runtime")]
[assembly: Galaktika.BI.Extensibility.IncludeAssembly("Ranet.Charting")]

namespace Galaktika.BI.Addin.VisifireChart
{
    using Galaktika.BI.Addin.VisifireChart.Design;
    using Galaktika.BI.Extensibility;
    using Galaktika.BI.Extensibility.Design;

    class AddinProvider : IExtension
    {
        public AddinProvider()
        {
            this.Enabled = true;
        }

        #region IExtension Members

        public string Name
        {
            get { return Localization.Str_AddinName; }
        }

        public string Description
        {
            get { return Localization.Str_AddinDescription; }
        }

        public System.Drawing.Image Image32
        {
            get { return Resources.Images.Addin32; }
        }

        public bool Enabled { get; set; }

        public string Vendor
        {
            get { return Localization.Str_AddinVenfor; }
        }

        public string Version
        {
            get { return "1.0"; }
        }

        IServiceProvider m_Services;
        List<CustomToolboxItem> m_TbItems = new List<CustomToolboxItem>();
        public void Initialize(IServiceProvider services)
        {
            m_Services = services;

            ICompilationService cs = (ICompilationService)services.GetService(typeof(ICompilationService));
            if (cs != null)
            {
                cs.RegisterTypeConverters(this, new ICompilationTypeConverter[]
                {
                    new Galaktika.BI.Addin.VisifireChart.Converters.SystemWindowsFormsHorizontalAlignmentConverter(),
                    new Galaktika.BI.Addin.VisifireChart.Converters.SystemWindowsFormsOrientationConverter(),
                    new Galaktika.BI.Addin.VisifireChart.Converters.SystemWindowsFormsVisualStylesVerticalAligmentConverter(),
                    new Galaktika.BI.Addin.VisifireChart.Converters.SystemEnumConverter()
                });
            }
            IUpdateableToolboxService ts = (IUpdateableToolboxService)services.GetService(typeof(IUpdateableToolboxService));
            if (ts != null)
            {
                ts.BeginUpdate();

                var item = new CustomToolboxItem(typeof(PivotChart));
                m_TbItems.Add(item);
                ts.AddToolboxItem(item, (string)item.Properties[CustomToolboxItem.CATEGORY_PROPERTY]);

                ts.EndUpdate();
            }

            IEnvDTEService envDTE = (IEnvDTEService)m_Services.GetService(typeof(IEnvDTEService));
            if (envDTE != null)
            {
                envDTE.RegisterBrickMapper(this,
                    "3B55C8FC-0802-4709-B4E6-941D940D4034",
                    new Mapper(),
                    new string[] 
                    {
                        "{945DD9BB-AC00-4d38-AF26-D26935CC1FF7}" // PivotChart guid
                    });
            }

        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            ICompilationService cs = (ICompilationService)m_Services.GetService(typeof(ICompilationService));
            if (cs != null)
            {
                cs.UnRegisterTypeConverters(this);
            }


            IUpdateableToolboxService ts = (IUpdateableToolboxService)m_Services.GetService(typeof(IUpdateableToolboxService));
            if (ts != null)
            {
                ts.BeginUpdate();
                foreach (CustomToolboxItem item in m_TbItems)
                {
                    ts.RemoveToolboxItem(item);
                }
                m_TbItems.Clear();
                ts.EndUpdate();
            }
        }

        #endregion
    }
}
